package com.xtgg.main;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.xtgg.R;
import com.xtgg.manager.BaseActivity;
import com.xtgg.util.ImageLoaderHelper;
import com.xtgg.widget.TouchImageView;

import android.media.AudioManager;
import android.os.Bundle;
import android.os.Parcelable;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.ImageView;

public class SingleImageShowActivity extends BaseActivity {
	// ------------闪图-----------------
	private ViewPager viewPager; // android-support-v4中的滑动组件
	private List<ImageView> imageViews = new ArrayList<ImageView>(); // 滑动的图片集合
	static public Bitmap mShowBitmap;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_image_show);

		viewPager = (ViewPager) findViewById(R.id.vp);
		viewPager.setOnPageChangeListener(new MyPageChangeListener());
		TouchImageView imageView = new TouchImageView(this);
		if(mShowBitmap == null)
		{
			ImageLoaderHelper.displayImage(R.drawable.img_default,imageView, getIntent().getExtras().getString("url"));
		}
		imageView.setMaxZoom(4f);
		imageViews.add(imageView);
		viewPager.setAdapter(new MyAdapter());// 设置填充ViewPager页面的适配器
	}

	private class MyPageChangeListener implements OnPageChangeListener {
		public void onPageSelected(int position) {
		}

		public void onPageScrollStateChanged(int arg0) {
		}

		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}
	}

	private class MyAdapter extends PagerAdapter {
		public MyAdapter() {
		}

		@Override
		public int getCount() {
			return imageViews.size();
		}

		@Override
		public Object instantiateItem(View arg0, int arg1) {
			((ViewPager) arg0).addView(imageViews.get(arg1));
			return imageViews.get(arg1);
		}

		@Override
		public void destroyItem(View arg0, int arg1, Object arg2) {
			((ViewPager) arg0).removeView((View) arg2);
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0 == arg1;
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {

		}

		@Override
		public Parcelable saveState() {
			return null;
		}

		@Override
		public void startUpdate(View arg0) {

		}

		@Override
		public void finishUpdate(View arg0) {

		}
	}
}
